﻿@model NigiriClub.WebUI.Models.FileModel

<script src="~/Scripts/jquery.form.min.js" type="text/javascript"></script>

<script>
    $(document)
        .on('change', '.btn-file :file', function () {
            var input = $(this),
            numFiles = input.get(0).files ? input.get(0).files.length : 1,
            label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
            input.trigger('fileselect', [numFiles, label]);
        });

    $(document).ready(function () {
        $('.btn-file :file').on('fileselect', function (event, numFiles, label) {

            var input = $(this).parents('.input-group').find(':text'),
                log = numFiles > 1 ? numFiles + ' files selected' : label;

            if (input.length) {
                input.val(log);
            } else {
                if (log) alert(log);
            }

        });
    });
	</script>

<div id="fileNames">
</div>

@using (Html.BeginForm("UploadSgf", "UploadFiles", FormMethod.Post,
    new { enctype = "multipart/form-data", @class = "uploadFileForm" }))
{  
    @Html.AntiForgeryToken()
    <span class="input-group">
        <span class="input-group-btn">

            <span class="file-input btn btn-primary btn-file btn-xs">Выбрать изображение
    @Html.TextBoxFor(model => model.file, new { type = "file", accept = ".sgf", multiple = "multiple" })
            </span>
        </span>
        <input type="text" class="form-control" readonly>
    </span>
        
    <button type="submit" class="btn btn-primary btn-xs">Загрузить</button>
}

@using (Html.BeginForm("UploadImage", "UploadFiles", FormMethod.Post,
    new { enctype = "multipart/form-data", @class = "uploadFileForm" }))
{  
    @Html.AntiForgeryToken()
    <span class="input-group">
        <span class="input-group-btn">

            <span class="file-input btn btn-primary btn-file btn-xs">Выбрать .sgf
    @Html.TextBoxFor(model => model.file, new { type = "file", accept = "image/*", multiple = "multiple" })
            </span>
        </span>
        <input type="text" class="form-control" readonly>
    </span>
        
    <button type="submit" class="btn btn-primary btn-xs">Загрузить</button>
}


<script>
    $(document).ready(function () {
        $('.uploadFileForm').ajaxForm(function (result) {
            var items = [];
            $.each(result.FileNames, function (key, val) {
                items.push('<li>' + val + '</li>');
            });

            $('<ul/>', {
                html: items.join(''), class: "list-unstyled"
            }).appendTo('#fileNames');
        });
    });
</script>
